<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'liaoTian.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

<script type="text/javascript">

var xmlHttp;
function createXMLHttpRequest(){
	if(window.ActiveXObject){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if(window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}
}

function tiJiao(){
	var content=document.getElementById("content").value;
	
    var url = "/LiaoTianSystem/chuLiAction.action?content="+content+"&ts="+new Date().getTime();
    
    createXMLHttpRequest();
	xmlHttp.onreadystatechange = tiJiao_change;
	url=encodeURI(url);
	url=encodeURI(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function tiJiao_change(){

	if(xmlHttp.readyState==4){
		if(xmlHttp.status ==200){
			tiJiao_update();
		}
	}
}
function tiJiao_update(){
    tiJiao_clear();
    var xml=xmlHttp.responseXML;
    
}
function tiJiao_clear(){
	document.getElementById("content").value="";
}



function check(){
    var url = "/LiaoTianSystem/checkAction.action?ts="+new Date().getTime();
    
    createXMLHttpRequest();
	xmlHttp.onreadystatechange = check_change;
	url=encodeURI(url);
	url=encodeURI(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
}
function check_change(){

	if(xmlHttp.readyState==4){
		if(xmlHttp.status ==200){
			check_update();
		}
	}
}
function check_update(){
    check_clear();
    
    var xml=xmlHttp.responseXML;
    
    var app_flags=xml.getElementsByTagName("app_flag");
    
    var app_flag=app_flags[0].firstChild==null?"":app_flags[0].firstChild.nodeValue;
    
    if(app_flag=="true"){//有人说话了，添加新的聊天内容
    	duQu();
    }
    
}
function check_clear(){
	
}



function duQu(){
    var url = "/LiaoTianSystem/duQuAction.action?ts="+new Date().getTime();
    
    createXMLHttpRequest();
	xmlHttp.onreadystatechange = duQu_change;
	url=encodeURI(url);
	url=encodeURI(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
}
function duQu_change(){

	if(xmlHttp.readyState==4){
		if(xmlHttp.status ==200){
			duQu_update();
		}
	}
}
function duQu_update(){
	
    duQu_clear();
    
    var xml=xmlHttp.responseXML;
    
    var app_contents=xml.getElementsByTagName("app_content");
    
    var app_content=app_contents[0].firstChild==null?"":app_contents[0].firstChild.nodeValue;
    
    if(app_content!=""){//有人说话了，添加新的聊天内容
    	document.getElementById("liaoTianContent").value=app_content;
    	setTimeout("chuLiEr()",2000);
    }
    
}
function duQu_clear(){
	
}




function chuLiEr(){
    var url = "/LiaoTianSystem/chuLiErAction.action?ts="+new Date().getTime();
    
    createXMLHttpRequest();
	xmlHttp.onreadystatechange = chuLiEr_change;
	url=encodeURI(url);
	url=encodeURI(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
}
function chuLiEr_change(){

	if(xmlHttp.readyState==4){
		if(xmlHttp.status ==200){
			chuLiEr_update();
		}
	}
}
function chuLiEr_update(){
    chuLiEr_clear();
    var xml=xmlHttp.responseXML;
}
function chuLiEr_clear(){
	
}



function start(){
	setInterval("check()","200");
}

</script>

  </head>
  
  <body onload="start()">

<table cellpadding="0" cellspacing="0" width="100%" style="font-size:10px">
	<tr>
		<td>

<textarea rows="20" cols="50" id="liaoTianContent" name="liaoTianContent">


</textarea>

		</td>
	</tr>
	<tr>
		<td>
			<input type="text" id="content" name="content">
			<input type="button" onclick="tiJiao()" value="提交">
		</td>
	</tr>
</table>



  </body>
</html>
